package com.alibaba.citrus.cr.platform.enhance.functions.diff.common.router;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.alibaba.citrus.cr.platform.enhance.facade.service.diff.common.DiffCheckRequest;

import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Component;

/**
 * 对账策略路由
 */
@Component
public class DiffStrategyRoute {

    private Map<String, DiffCheckProcessor> map = new HashMap<>();



    @Resource
    private List<DiffCheckProcessor> diffCheckProcessorList;


    /**
     * 获取处理器
     *
     * @param diffCheckRequest
     * @return
     */
    public DiffCheckProcessor obtainProcessor(DiffCheckRequest diffCheckRequest) {
        if (MapUtils.isEmpty(map)) {
            for (DiffCheckProcessor diffCheckProcessor : diffCheckProcessorList) {
                map.put(diffCheckProcessor.obtainStrategyRoute(), diffCheckProcessor);
            }
        }
        return map.get(diffCheckRequest.getStrategyRoute());
    }

}
